<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            background-color: rgb(241, 242, 243)
        }

        .el-header {
            background-color: white
        }

        #footer_center h3 {
            color: white
        }

        #footer_center p {
            margin: 0
        }

        [v-cloak] {
            display: none
        }
    </style>
</head>
<body>
<!--当Vue框架文件加载完成后会自动删除掉所有元素的v-cloak属性-->
<div id="app" v-cloak>
    <el-container>
        <my-header></my-header>
        <el-main style="width: 1200px;margin: 0 auto">

            <el-row gutter="10">
                <el-col span="4">
                    <el-card style="height: 500px">
                        <el-menu @select="handleSelect" style="border: 0" active-text-color="orange"
                                 default-active="2">
                            <el-menu-item index="1">个人信息</el-menu-item>
                            <el-menu-item index="2">稿件管理</el-menu-item>
                        </el-menu>
                    </el-card>
                </el-col>
                <el-col span="20">
                    <el-card >
                        <template>
                            <el-tabs type="card">
                                <el-tab-pane label="烘焙食谱">
                                    <el-button type="primary" @click="location.href='post.html?type=1'">发布食谱</el-button>
                                    <el-table :data="recipeArr">
                                        <el-table-column type="index" label="编号"></el-table-column>
                                        <el-table-column label="标题" prop="title" width="150px"></el-table-column>
                                        <el-table-column label="摘要" prop="brief" width="300px"></el-table-column>
                                        <el-table-column label="封面" width="60px">
                                            <template slot-scope="scope">
                                                <img :src="scope.row.imgUrl" width="50px">
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="类型" prop="categoryName"></el-table-column>
                                        <el-table-column label="浏览量" prop="viewCount"></el-table-column>
                                        <el-table-column label="评论量" prop="commentCount"></el-table-column>
                                        <el-table-column label="发布时间" prop="createTime"></el-table-column>
                                        <el-table-column label="操作" width="200px" fixed="right">
                                            <template slot-scope="scope">
                                                <el-button size="mini" type="success" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                                                <el-button size="mini" type="danger" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-tab-pane>
                                <el-tab-pane label="烘焙视频">
                                    <el-button type="primary" @click="location.href='post.html?type=2'">发布视频</el-button>
                                    <el-table :data="videoArr">
                                        <el-table-column type="index" label="编号"></el-table-column>
                                        <el-table-column label="标题" prop="title" width="150px"></el-table-column>
                                        <el-table-column label="摘要" prop="brief" width="300px"></el-table-column>
                                        <el-table-column label="封面" width="60px">
                                            <template slot-scope="scope">
                                                <img :src="scope.row.imgUrl" width="50px">
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="类型" prop="categoryName"></el-table-column>
                                        <el-table-column label="浏览量" prop="viewCount"></el-table-column>
                                        <el-table-column label="评论量" prop="commentCount"></el-table-column>
                                        <el-table-column label="发布时间" prop="createTime"></el-table-column>
                                        <el-table-column label="操作" width="200px" fixed="right">
                                            <template slot-scope="scope">
                                                <el-button size="mini" type="success" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                                                <el-button size="mini" type="danger" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-tab-pane>
                                <el-tab-pane label="行业资讯">
                                    <el-button type="primary" @click="location.href='post.html?type=3'">发布资讯</el-button>
                                    <el-table :data="infoArr">
                                        <el-table-column type="index" label="编号"></el-table-column>
                                        <el-table-column label="标题" prop="title" width="150px"></el-table-column>
                                        <el-table-column label="摘要" prop="brief" width="300px"></el-table-column>
                                        <el-table-column label="封面" width="60px">
                                            <template slot-scope="scope">
                                                <img :src="scope.row.imgUrl" width="50px">
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="类型" prop="categoryName"></el-table-column>
                                        <el-table-column label="浏览量" prop="viewCount"></el-table-column>
                                        <el-table-column label="评论量" prop="commentCount"></el-table-column>
                                        <el-table-column label="发布时间" prop="createTime"></el-table-column>
                                        <el-table-column label="操作" width="200px" fixed="right">
                                            <template slot-scope="scope">
                                                <el-button size="mini" type="success" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
                                                <el-button size="mini" type="danger" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </el-tab-pane>
                            </el-tabs>
                        </template>

                    </el-card>

                </el-col>
            </el-row>

        </el-main>
        <el-footer style="background-color: #2f3234;height: 280px;padding: 50px 0">
            <div style="width: 1200px;margin: 0 auto;text-align: center;color: #666">
                <el-row gutter="20">
                    <el-col span="8">
                        <img src="imgs/icon.png">
                        <p>教程灵感就看烘焙坊</p>
                        <p>烘焙行业网络社区平台</p>
                        <p>全国百城上千个职位等你来</p>
                    </el-col>
                    <el-col id="footer_center" span="8">
                        <el-row gutter="20">
                            <el-col span="8">
                                <h3>关于我们</h3>
                                <p>烘焙学院</p>
                                <p>烘焙食谱</p>
                                <p>分类信息</p>
                                <p>求职招聘</p>
                                <p>社区交流</p>
                            </el-col>
                            <el-col span="8">
                                <h3>服务与支持</h3>
                                <p>练习我们</p>
                                <p>广告投放</p>
                                <p>用户协议</p>
                                <p>友情链接</p>
                                <p>在线反馈</p>
                                <p>我发投稿</p>
                            </el-col>
                            <el-col span="8">
                                <h3>底部导航</h3>
                                <p>Archiver</p>
                                <p>手机版</p>
                                <p>小黑屋</p>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col span="8">
                        <p style="font-size: 60px;margin: 0">
                            <span style="color: orange">烘焙</span>坊
                        </p>
                        <p>烘焙行业网络社区平台</p>
                    </el-col>
                </el-row>
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
<script src="js/header.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
                recipeArr: [],
                videoArr:[],
                infoArr:[]
            }
        },
        methods: {
            handleDelete(i,c){
                if (confirm("您确认删除此内容吗?")){
                    axios.post("/v1/contents/"+c.id+"/delete").then(function (response) {
                        if (response.data.code==1){
                            v.$message.success("删除完成!");
                            //让表格中删除数据
                            switch (c.type) {
                                case 1://食谱
                                    v.recipeArr.splice(i,1);
                                    break;
                                case 2://视频
                                    v.videoArr.splice(i,1);
                                    break;
                                case 3://资讯
                                    v.infoArr.splice(i,1);
                                    break;
                            }
                        }
                    })
                }
            },
            handleEdit(i,c){
                location.href = "/post.html?type="+c.type+"&id="+c.id;
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            handleSelect(key, keyPath) {
                if (key == 1) {
                    location.href = "personal.html";
                } else {
                    location.href = "content-management.html";
                }
            }
        },
        created:function () {
            //得到当前登录的用户信息
            let user = localStorage.user?JSON.parse(localStorage.user):null;
            if (user==null){
                alert("请先登录!");
                location.href="/login.html";
                return;
            }

            //请求食谱数据
            axios.get("/v1/contents/1/"+user.id+"/management").then(function (response) {
                if (response.data.code==1){
                    v.recipeArr = response.data.data;
                }
            })
            //请求视频数据
            axios.get("/v1/contents/2/"+user.id+"/management").then(function (response) {
                if (response.data.code==1){
                    v.videoArr = response.data.data;
                }
            })
            //请求资讯数据
            axios.get("/v1/contents/3/"+user.id+"/management").then(function (response) {
                if (response.data.code==1){
                    v.infoArr = response.data.data;
                }
            })
        }
    })
</script>
</html>